﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;

namespace LPLS.WPFBaseLibrary
{
    public class StringToBoolConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value is string stringValue)
            {
                // 尽管通常我们使用ToLower()来处理大小写，但根据你的需求，这里仅匹配"true"和"FALSE"
                if (stringValue?.ToLower() == "true")
                {
                    return true;
                }
                else if (stringValue?.ToUpper() == "FALSE")
                {
                    return false;
                }
            }
            throw new InvalidOperationException("Cannot convert to bool");
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value is bool boolValue)
            {
                return boolValue.ToString();
            }
            throw new InvalidOperationException("Cannot convert back to string");
        }
    }
}
